<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物流单号">
          <a-input placeholder="请输入物流单号" v-model="shipmentNumber"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-textarea placeholder="请输入备注" v-model="remark"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import {httpAction, postAction} from '@/api/manage'
  import ATextarea from "ant-design-vue/es/input/TextArea";

  export default {
    name: "PmsIntegralProductOrderModal",
    components: {ATextarea},
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {},
        record: {},
        shipmentNumber: "",
        remark: "",
        orderStatus: 2,
        url: {
          add: "/order/pmsIntegralProductOrder/add",
          edit: "/order/pmsIntegralProductOrder/edit",
          updateOrderStatus: "/order/pmsIntegralProductOrder/updateOrderStatus",
        },
      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.record = {};
        this.shipmentNumber = "";
        this.remark = "";
        this.form.resetFields();
        // this.model = Object.assign({}, record);
        this.record = record;
        this.visible = true;
        // this.$nextTick(() => {
        //   this.form.setFieldsValue(pick(this.model, 'userId', 'productId', 'orderNo', 'orderStatus', 'orderAmount', 'productNum', 'productAmount', 'receiverName', 'receiverPhone', 'receiverProvinceId', 'receiverCityId', 'receiverAreaId', 'receiverProvinceName', 'receiverCityName', 'receiverAreaName', 'receiverAddress', 'remark', 'cancelDescription', 'delFlag'))
        //   //时间格式化
        // });
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        let pushStatus = true;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          console.info(this.shipmentNumber);
          if (!this.shipmentNumber) {
            console.info("进异常");
            this.$message.error('物流单号不能为空！')
            pushStatus = false;
          }
          if (!err && pushStatus) {
            that.confirmLoading = true;
            let httpUrl = this.url.updateOrderStatus;
            let method = 'post';
            let formData = {
              id: this.record.id,
              orderStatus: this.orderStatus,
              shipmentNumber: this.shipmentNumber,
              remark: this.remark,
            };
            //时间格式化
            httpAction(httpUrl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel() {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>